﻿<%@ Page Title="" Language="C#" MasterPageFile="~/DeveloperSite.Master" AutoEventWireup="true" 
    CodeBehind="Users.aspx.cs" Inherits="UNDP_Projects.CO.Users" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <asp:EntityDataSource ID="EntityDataSource1" runat="server" 
        ConnectionString="name=UNDPEntities" DefaultContainerName="UNDPEntities" 
        EnableDelete="True" EnableUpdate="true" EnableFlattening="False" EntitySetName="users" 
        Include="program">
    </asp:EntityDataSource>

    <%--<asp:EntityDataSource ID="RolesDataSource" runat="server" 
        ConnectionString="name=UNDPEntities" DefaultContainerName="UNDPEntities" 
        EnableFlattening="False" EntitySetName="roles" 
        Select="it.[role_id], it.[role1]">
    </asp:EntityDataSource>--%>

    <asp:EntityDataSource ID="ProgrammeDataSource" runat="server" 
        ConnectionString="name=UNDPEntities" DefaultContainerName="UNDPEntities" 
        EnableFlattening="False" EntitySetName="programs">
    </asp:EntityDataSource>

    <asp:EntityDataSource ID="ProjectDataSource" runat="server" 
        ConnectionString="name=UNDPEntities" DefaultContainerName="UNDPEntities" 
        EnableFlattening="False" EntitySetName="projects" 
        Select="it.[project_id], it.[project1]">
    </asp:EntityDataSource>
    
    <div style="height:2em;">
        <div style="float:left;">
            <asp:Label ID="ContextLabel" runat="server" Text="USERS" CssClass="ContentHead"></asp:Label>
        </div>
        <% if (User.IsInRole("Administrator"))
           { %>
        <div style="float:right;">
            <asp:Button ID="AddUserButton" runat="server" Text="Add User" OnClick="AddUserButton_Click" />
        </div>
        <% }
           else
           { %>
            <div style="float:right;">
                <asp:Button ID="Button1" runat="server" Text="Add User" OnClick="AddUserButton_Click" Enabled="false" />
            </div>
        <% } %>
    </div>

    <% if (User.IsInRole("Administrator"))
       { %>
    <asp:GridView ID="GridView1" runat="server" DataSourceID="EntityDataSource1" 
            AutoGenerateColumns="False" CssClass="NewGrid" ShowFooter="True" 
            DataKeyNames="user_id">
    <AlternatingRowStyle CssClass="NewGridAlt" />
    <Columns>
        <asp:TemplateField HeaderText="EMAIL">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("user_email") %>' Width="110px"></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label5" runat="server" Text='<%# Bind("user_email") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="FIRST NAME">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("first_name") %>' Width="80px"></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label6" runat="server" Text='<%# Bind("first_name") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="LAST NAME">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("last_name") %>' Width="80px"></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label7" runat="server" Text='<%# Bind("last_name") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="PROGRAMME">
            <EditItemTemplate>
                <asp:DropDownList ID="ProgrammeList" Width="200px" runat="server" DataSourceID="ProgrammeDataSource" 
                    DataTextField="program1" DataValueField="program_id" 
                    AppendDataBoundItems="true" SelectedValue='<%# Bind("program_id") %>'>
                <asp:ListItem Text="NA" Value="" Enabled="true"></asp:ListItem>
                </asp:DropDownList>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label4" runat="server" Text='<%# Eval("program.program1") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>

        <asp:BoundField DataField="project_id" HeaderText="PROJECT(S)" ReadOnly="true" />
        <%--<asp:TemplateField HeaderText="PROJECT">
            <EditItemTemplate>
                <asp:DropDownList ID="ProjectList" Width="200px" runat="server" DataSourceID="ProjectDataSource" 
                    DataTextField="project1" DataValueField="project_id" 
                    AppendDataBoundItems="true" SelectedValue='<%# Bind("project_id") %>'>
                <asp:ListItem Text="NA" Value="" Enabled="true"></asp:ListItem>
                </asp:DropDownList>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Eval("project.project1") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>--%>
        <asp:BoundField DataField="roles" HeaderText="ROLE(S)" ReadOnly="true"></asp:BoundField>
        <%--<asp:TemplateField HeaderText="ROLE">
            <EditItemTemplate>
                <asp:ListBox ID="RolesListBox" runat="server" 
                    DataSourceID="RolesDataSource" 
                    SelectionMode="Multiple" 
                    DataTextField="role1" 
                    DataValueField="role1">
                </asp:ListBox>
                <asp:DropDownList ID="RolesList" runat="server" 
                    DataSourceID="RolesDataSource" 
                    DataTextField="role1" 
                    DataValueField="role_id" 
                    SelectedValue='<%# Bind("roles") %>' 
                    Width="8em">
                </asp:DropDownList>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("roles") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>--%>
        <asp:TemplateField HeaderText="ACTIVE">
            <EditItemTemplate>
                <asp:DropDownList ID="ActiveList" runat="server" SelectedValue='<%# Bind("active") %>'>
                    <asp:ListItem Value="True" Text="YES"></asp:ListItem>
                    <asp:ListItem Value="False" Text="NO"></asp:ListItem>
                </asp:DropDownList>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Bind("active") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:CommandField ShowEditButton="true" ButtonType="Button" HeaderText="EDIT" />
        <asp:CommandField ShowDeleteButton="true" ButtonType="Button" HeaderText="DELETE" />

    </Columns>
    <FooterStyle CssClass="NewGridFooter" />
    </asp:GridView>
    <% }
       else
       { %>
            <asp:GridView ID="GridView2" runat="server" DataSourceID="EntityDataSource1" 
            AutoGenerateColumns="False" CssClass="NewGrid" ShowFooter="True" 
            DataKeyNames="user_id">
    <AlternatingRowStyle CssClass="NewGridAlt" />
    <Columns>
        <asp:TemplateField HeaderText="EMAIL">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("user_email") %>' Width="110px"></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label5" runat="server" Text='<%# Bind("user_email") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="FIRST NAME">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("first_name") %>' Width="80px"></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label6" runat="server" Text='<%# Bind("first_name") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="LAST NAME">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("last_name") %>' Width="80px"></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label7" runat="server" Text='<%# Bind("last_name") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="PROGRAMME">
            <EditItemTemplate>
                <asp:DropDownList ID="ProgrammeList" Width="200px" runat="server" DataSourceID="ProgrammeDataSource" 
                    DataTextField="program1" DataValueField="program_id" 
                    AppendDataBoundItems="true" SelectedValue='<%# Bind("program_id") %>'>
                <asp:ListItem Text="NA" Value="" Enabled="true"></asp:ListItem>
                </asp:DropDownList>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label4" runat="server" Text='<%# Eval("program.program1") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>

        <asp:BoundField DataField="project_id" HeaderText="PROJECT(S)" ReadOnly="true" />
        <%--<asp:TemplateField HeaderText="PROJECT">
            <EditItemTemplate>
                <asp:DropDownList ID="ProjectList" Width="200px" runat="server" DataSourceID="ProjectDataSource" 
                    DataTextField="project1" DataValueField="project_id" 
                    AppendDataBoundItems="true" SelectedValue='<%# Bind("project_id") %>'>
                <asp:ListItem Text="NA" Value="" Enabled="true"></asp:ListItem>
                </asp:DropDownList>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Eval("project.project1") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>--%>
        <asp:BoundField DataField="roles" HeaderText="ROLE(S)" ReadOnly="true"></asp:BoundField>
        <%--<asp:TemplateField HeaderText="ROLE">
            <EditItemTemplate>
                <asp:ListBox ID="RolesListBox" runat="server" 
                    DataSourceID="RolesDataSource" 
                    SelectionMode="Multiple" 
                    DataTextField="role1" 
                    DataValueField="role1">
                </asp:ListBox>
                <asp:DropDownList ID="RolesList" runat="server" 
                    DataSourceID="RolesDataSource" 
                    DataTextField="role1" 
                    DataValueField="role_id" 
                    SelectedValue='<%# Bind("roles") %>' 
                    Width="8em">
                </asp:DropDownList>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("roles") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>--%>
        <asp:TemplateField HeaderText="ACTIVE">
            <EditItemTemplate>
                <asp:DropDownList ID="ActiveList" runat="server" SelectedValue='<%# Bind("active") %>'>
                    <asp:ListItem Value="True" Text="YES"></asp:ListItem>
                    <asp:ListItem Value="False" Text="NO"></asp:ListItem>
                </asp:DropDownList>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Bind("active") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText="EDIT" ShowHeader="False">
            <ItemTemplate>
                <asp:Button ID="Button1" runat="server" CausesValidation="False" 
                    CommandName="Edit" Text="Edit" Enabled="false" />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:Button ID="Button1" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                &nbsp;<asp:Button ID="Button2" runat="server" CausesValidation="False" 
                    CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="DELETE" ShowHeader="False">
            <ItemTemplate>
                <asp:Button ID="Button2" runat="server" CausesValidation="False" 
                    CommandName="Delete" Text="Delete" Enabled="false" />
            </ItemTemplate>
        </asp:TemplateField>

    </Columns>
    <FooterStyle CssClass="NewGridFooter" />
    </asp:GridView>
    <% } %>

</asp:Content>
